package com.morizhang.merchanmanager.api.utils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.morizhang.merchanmanager.api.bean.ErrorDefinition;
import com.morizhang.merchanmanager.api.bean.MerChanManagerException;

public class ErrorUtils {
    public static MerChanManagerException convertErrorToException(ErrorDefinition error) {
        MerChanManagerException merChanManagerException = new MerChanManagerException();
        merChanManagerException.setExceptionMessage(error.getErrorMessage());
        merChanManagerException.setErrorDefinition(error);
        return merChanManagerException;
    }

    public static JSONObject convertErrorToJsonForm(ErrorDefinition error) {
        JSONObject errorInfo = new JSONObject();
        errorInfo.put("errorCode", error.getErrorCode());
        errorInfo.put("errorName", error.getErrorName());
        errorInfo.put("errorClass", error.getErrorClass());
        errorInfo.put("errorMessage", error.getErrorMessage());
        JSONArray data = new JSONArray();
        data.add(errorInfo);
        JSONObject result = new JSONObject();
        result.put("data", data);
        return result;
    }
}
